<?php

// wf_list.php
// Michael Baker
// 2010.07.12
//
// List workflows

session_start();

define("IN_MDM", true);
define("CUR_PAGE_TITLE", "Workflow management");
define("CUR_FLAG", "wf.list");

include '../includes/all.php';
include 'inc/header.php';

?>
<h2>Workflow list</h2>
<div style="text-align: right;"><a href="wf_create.php">&raquo; Create workflow</a></div>
<table class="type2p" cellspacing="1">
  <col class="col2" /><col class="col2" /><col class="col2" /><col class="col2" /><col class="col1" />
  
  <thead>
    <tr>
      <th>Workflow Title</th>
      <th>Initial IP</th>
      <th>Final IP</th>
      <th>Status</th>
      <th>Controls</th>
    </tr>
  </thead>
  
  <tbody>
    <?php
    
    // Retrieve ID=>Title assoc. array of workflows
    $wf_list = $dbase->list_workflows();
    asort($wf_list); // sort alphabetically (use ksort for ID sorting)
    
    $has_wf_del  = has_flag( $uid, "wf.del" );
    $has_wf_view = has_flag( $uid, "wf.view" );
    $has_n_view  = has_flag( $uid, "n.view"  );
    
    foreach ( $wf_list as $id => $title ) {
      $wf = $dbase->get_workflow($id);
      $children = $wf->get_endpoints();
      
      $init_id = $children[0]->get_id();
      $fin_id  = $children[1]->get_id();
      
      $init = $children[0]->get_address();
      $fin  = $children[1]->get_address();
      
      echo "<tr>";
      
      $link1 = $has_wf_view ? ui_create_link( $title, "wf_view.php?id=$id"    ) : $title;
      $link2 = $has_n_view  ? ui_create_link( $init, "n_view.php?id=$init_id" ) : $init;
      $link3 = $has_n_view  ? ui_create_link( $fin, "n_view.php?id=$fin_id"   ) : $fin;
      $link4 = $has_wf_del  ? ui_create_link( "Remove", "wf_del.php?id=$id"   ) : "Remove";
      
      echo "<td>$link1</td>";
      echo "<td>$link2</td>";
      echo "<td>$link3</td>";
      
      echo "<td style=\"text-align: center;\"><a href=\"../status.php?wf=$id&amp;tf=1\" target=\"_new\">Click</a></td>";
      echo "<td style=\"text-align: center;\">" . $link4 . "</td>";
      echo "</tr>";
    }
     
    ?>
  </tbody>
</table>

<?php include 'inc/footer.php'; ?>